package com.crrc.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class CodeGenerator {

    public static void main(String[] args) {
        String url = "jdbc:postgresql://192.168.71.8:10432/wls_20241112";
//        String username = "dwadmin";
//        String password = "dwadmin@2021";

//                String url = "jdbc:clickhouse://192.168.71.198:8123/default";
        String username = "postgres";
        String password = "123456";

//        List<String> tableList = Stream.of("m_res_ccyc", "m_res_jkzt", "m_res_xxmb", "m_res_xxzq", "m_res_ycmh").collect(Collectors.toList());
        String tableNames = "fault_cd_mapping";
        List<String> tableList = Arrays.stream(tableNames.split(",")).collect(Collectors.toList());
//        List<String> tableList = Stream.of().collect(Collectors.toList());

        String tablePrefix = "";

        FastAutoGenerator.create(new DataSourceConfig.Builder(url, username, password)
                        .schema("public"))

                .globalConfig(builder -> {
                    builder.author("xin")
                            .outputDir(System.getProperty("user.dir") + "/src/main/java")
                            .commentDate("yyyy-MM-dd hh:mm:ss")
                            .disableOpenDir();   //注释日期
                })
                .packageConfig(builder -> {
                    builder.parent("com.crrc")
                            .entity("model.entity")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .xml("mapper")
//                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.xml,System.getProperty("user.dir") + "/src/main/resources/mapper" ));
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tableList)
                            .addTablePrefix(tablePrefix)
                            .entityBuilder().enableLombok()
                            .enableFileOverride()
                            .mapperBuilder()
                            .enableMapperAnnotation();

                })
                .execute();
    }
}
